Skip to content

feat(metascraper-x): use X post card as image for posts without media - #889

Closed
Kikobeats wants to merge 1 commit into
masterfrom
Kikobeats/x-post-card
Closed

Kikobeats wants to merge 1 commit into
masterfrom
Kikobeats/x-post-card

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

What

For /<user>/status/<id> URLs, metascraper-x now falls back to the card X renders for every post:

https://jf.x.com/images/post/<id>.png   (1200x630 PNG)

This is the same image Slack shows when unfurling an X link.

Why

X only puts that card in og:image when the request comes from a link-preview bot:

Who fetches the post og:image
Slackbot / Twitterbot https://jf.x.com/images/post/<id>.png
Browser UA author avatar (profile_images/..._400x400.jpg)

Microlink's X syndication provider emits no og:image at all for text-only posts, so today
https://api.microlink.io/?url=https://x.com/Kikobeats/status/2110627638049910905 returns image: null.

Slack adds nothing on top: the PNG from slack-imgs.com is byte-identical to the one from jf.x.com (same sha256), so we point at X directly.

Precedence

Media still wins: jsonld image, video poster, tweet photo, link card, and og:image when it is real media (pbs.twimg.com/media/..., card_img, ...). The post card replaces og:image only when that is the avatar (/profile_images/), X's generic logo (/rweb/ssr/default/), or missing. Profile URLs are unchanged.

Tests

  • New from a post without media uses the post card test with the syndication HTML the API produces (fails on master, image is undefined).
  • 3 snapshots updated, all text-only posts: generic logo/avatar -> post card.
  • pnpm test in packages/metascraper-x: 20 passed. standard clean.
  • Card URLs used in the snapshots return 200 image/png. Missing ids return 404.

Caveat

jf.x.com is not a documented API. It is what X hands to crawlers today. If X changes it, posts without media go back to the previous image.

🤖 Generated with Claude Code


Note

Low Risk
Scoped to X image metadata selection in metascraper-x; relies on undocumented jf.x.com URLs that could break if X changes crawler behavior.

Overview
metascraper-x now derives share images for status URLs via getShareImage, which still prefers JSON-LD, video posters, and in-page media, but treats og:image as real media only when it is not an avatar (/profile_images/) or X’s generic preview (/rweb/ssr/default/). Otherwise it falls back to https://jf.x.com/images/post/<statusId>.png, fixing text-only / syndicated posts that omit og:image or only expose profile/generic images.

Tests add syndication HTML without og:image and update snapshots so text-only posts expect the post card instead of generic logo or avatar URLs.

Reviewed by Cursor Bugbot for commit 03be303. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • X posts without a usable media image now display a post-specific preview image instead of a generic or profile image. Non-post pages retain their existing image fallback behavior.

X renders a 1200x630 card for every post at
https://jf.x.com/images/post/<id>.png and advertises it as og:image to
link-preview bots (Slackbot, Twitterbot). Non-bot HTML points og:image at
the author avatar or a generic X logo instead, and the syndication-based
HTML has no og:image at all, so text-only posts ended up with a weak image
or none.

Media (jsonld, video poster, tweet photo, link card, real og:image media)
still wins. The post card replaces og:image only when that is the avatar or
the generic logo, or when it is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e71743c7-2ac9-4ea7-b248-4172e77723b3
📥 Commits

Reviewing files that changed from the base of the PR and between 82d5233 and 03be303.

⛔ Files ignored due to path filters: 1
  • packages/metascraper-x/test/snapshots/index.js.snap is excluded by !**/*.snap
📒 Files selected for processing: 4
  • packages/metascraper-x/src/index.js
  • packages/metascraper-x/test/fixtures/post-syndication.html
  • packages/metascraper-x/test/index.js
  • packages/metascraper-x/test/snapshots/index.js.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The X scraper now derives post-card image URLs for status pages when the Open Graph image is a profile or default image. A new test and updated snapshots verify the selected images.

Changes: X post image selection

Layer / File(s) Summary
Status image selection
packages/metascraper-x/src/index.js
The image rule passes the page URL to getShareImage as its final fallback. For status URLs, the helper uses a non-profile, non-default Open Graph image when available; otherwise, it returns the post-card URL.
Post image validation
packages/metascraper-x/test/fixtures/post-syndication.html, packages/metascraper-x/test/index.js, packages/metascraper-x/test/snapshots/index.js.md
A test checks the post-card URL using the syndication fixture. Three snapshots now use post-specific image URLs.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to 03be3

The change adds a tested fallback for text-only posts while retaining existing image-source precedence. No concrete merge-blocking behavior is established; it appears ready for normal checks.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using X post-card images for posts without media.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 95.033% — Kikobeats/x-post-card into master. No base build found for master.

@Kikobeats Kikobeats closed this Oct 15, 2026
@Kikobeats
Kikobeats deleted the Kikobeats/x-post-card branch October 15, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants